$(function () {

  const layer = layui.layer



  $('form').on('submit', async function (e) {
    e.preventDefault()



    const username = document.querySelector('#username').value.trim()
    const password = document.querySelector('#password').value.trim()
    const phone = document.querySelector('#phone').value.trim()
    const sex = Number(document.querySelector('input[name=sex]:checked').value)
    const vip = Number(document.querySelector('input[name=vip]:checked').value)
    const question = document.querySelector('#question').value.trim()
    const answer = document.querySelector('#answer').value.trim()

    if (username.length <= 0 || password.length <= 0 || phone.length <= 0 || question.length <= 0 || answer.length <= 0) {
      return alert('输入内容不可为空')
    }

    const dataObj = { username, password, phone, sex, vip, question, answer }

    const { data } = await axios.post('http://124.223.14.236:3001/api/user/reg', dataObj)
    console.log(data);
    if (!data.success) {
      return layer.msg(data.msg)
    }
    layer.msg('注册成功!')
    location.href = '/01-loginBaseCode/login.html'

  })

})